package com.tencent.qf.systembiz.controller;

import com.alibaba.fastjson.JSON;
import com.tencent.qf.common.log.ErrorLog;
import com.tencent.qf.common.pojo.HttpResult;
import com.tencent.qf.mybatis.pojo.PageRequest;
import com.tencent.qf.mybatis.pojo.PageResult;
import com.tencent.qf.systembiz.service.ErrorLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.tencent.qf.common.pojo.HttpResult.success;

/**
 * Copyright (C) 2022 Limited, a Tencent company. All rights reserved.
 *
 * @author p_htaozhou@tencent.com
 * @create: 2022/9/8 17:36
 */
@RestController
@RequestMapping("/system/errorLog")
@Api(tags = "错误日志管理")
@Slf4j
public class ErrorLogController {

    @Resource
    private ErrorLogService errorLogService;

    @PostMapping("/getErrorLogList")
    @ApiOperation("获取日志列表")
    public HttpResult<PageResult<ErrorLog>> getErrorLogList(@RequestBody @Valid PageRequest<ErrorLog> request) {
        log.info("ErrorLogController.getErrorLogList request:{}", JSON.toJSONString(request));
        return success(errorLogService.getAllErrorLog(request));
    }

    @GetMapping("/test")
    @ApiOperation("测试")
    public HttpResult<String> test() {
        return success("test");
    }
}
